package com.ruoyi.common.enums;

import com.ruoyi.common.exception.ServiceException;
import lombok.Getter;

import java.util.Arrays;

@Getter
public enum SexEnum implements BaseInteger{
    MALE(0, "男"),
    FEMALE(1, "女"),
    UNKNOWN(2, "未知");
    private final Integer code;
    private final String desc;
    SexEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 可选：每个枚举类可以定义自己的fromCode方法
    public static SexEnum fromCode(Integer code) {
        return BaseInteger.fromCode(SexEnum.class, code);
    }


    @Override
    public SexEnum valOf(Integer code) {
        return Arrays.stream(SexEnum.values()).filter(item -> item.code.equals(code)).findFirst().orElseThrow(() -> new ServiceException("枚举转换异常"));
    }
}
